package com.example.dou2204.baseMVVM;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

public abstract class BaseFragment<VBD extends ViewDataBinding,VM extends BaseViewModel> extends Fragment {
    protected VBD binding;
    protected VM viewModel;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater,bindLayout(),container,false);
        viewModel = new ViewModelProvider(this).get(getViewModel());
        initView();
        initData();
        return binding.getRoot();
    }
    protected abstract void initData();//初始化数据请求

    protected abstract void initView();//初始化控件

    protected abstract int bindLayout();//绑定控件
    protected abstract Class<VM> getViewModel();//绑定ViewModel
}
